package com.issac.controller;

import com.issac.common.R;
import com.issac.dto.SearchFormDto;
import com.issac.entity.Fruit;
import com.issac.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName GoodsController
 * @Author zy
 * @Date 2021/11/1 16:18
 * @Description 添加商品即水果
 * @Version 1.0
 */
@RestController
public class GoodsController {
    @Autowired
    GoodsService goodsService;

    // 添加商品信息
    @PostMapping("/addGoods")
    public R addGoods(@RequestBody Fruit fruit){
        System.out.println("addGoods..............");

        return goodsService.addFruit(fruit);
    }

    // 删除商品信息 同时需删除其附属品
    @GetMapping("/deleteGoodsById")
    public R deleteGoods(@RequestParam("fruitId") String fruitId){
        return goodsService.deleteGoodsById(fruitId);
    }

    // 修改商品信息
    @PostMapping("/updateGoods")
    public R updateGoods(@RequestBody Fruit fruit){
        return goodsService.updateFruit(fruit);
    }

    // 查询全部商品信息
    @GetMapping("/selectAllGoods")
    public R selectAllGoods(){
        return goodsService.selectAllGoods();
    }

    // 分页查询
    @GetMapping("selectPageGoods")
    public R selectPageGoods(@RequestParam("page") int page,@RequestParam("size") int size){
        return goodsService.selectPageGoods(page,size);
    }

    // 根据条件模糊查询
    @PreAuthorize("hasAuthority('admin')")
    @PostMapping("/searchGoodsLike")
    public R selectGoodsLike(@RequestBody SearchFormDto dto){
        return goodsService.selectGoodsLike(dto);
    }
}
